package com.lianbang.staff.vm

import androidx.lifecycle.LiveData
import cn.ubest.mvvmcore.base.BaseListViewModel
import cn.ubest.mvvmcore.bean.ResultState
import cn.ubest.mvvmcore.interfaces.RequestHandler1Impl
import com.lianbang.staff.bean.OrderListBean
import com.lianbang.staff.bean.ShopOrderDetailBean
import com.lianbang.staff.model.OrderModel

/**
 * Created by maoqi on 2021/1/14.
 */
class OrderVM : BaseListViewModel<OrderModel>() {

    override fun loadData(isInit: Boolean, vararg arg: Any) {
        val state = arg[0] as Int
        getOrderList(state)
    }

    private fun getOrderList(state: Int) {
        requestWithLife(object : RequestHandler1Impl<List<OrderListBean>>(this) {
            override suspend fun request1(): List<OrderListBean> {
                return mModel.getOrderList(state, curPageNum, pageSize, "").resolveWrapper()
            }

            override fun onSuccess(t: List<OrderListBean>) {
                setData(t)
            }
        })
    }

    fun getOrderDetail(id:Int): LiveData<ResultState<ShopOrderDetailBean>> {
        return requestWithLife {
            mModel.getOrderDetail(id).resolveWrapper()
        }
    }

    fun confirmShopOrder(id: Int,
                         status: Int,
                         pay_price: Float): LiveData<ResultState<Boolean>> {
        return requestWithLife {
            mModel.confirmShopOrder(id,status,pay_price).resolveWrapper()
        }
    }
}